/**
* 版权声明：睿商(厦门)科技股份有限公司 版权所有 违者必究
* 日    期：2021-07-06
*/
package com.rzico.admin.service;

import com.rzico.admin.entity.Project;
import com.rzico.base.BaseMapper;
import com.rzico.base.impl.BaseServiceImpl;
import com.rzico.admin.entity.Company;
import com.rzico.core.entity.SysUser;
import com.rzico.core.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.rzico.admin.mapper.CompanyMapper;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <pre>
 * 项目活动记录表业务类
 * </pre>
 *
 * @author Rzico Boot
 * @version 1.0
 */
@Service
public class CompanyService extends BaseServiceImpl<Company, String> {

    @Autowired
    private CompanyMapper companyMapper;

    @Autowired
    private SysUserService sysUserService;

    @Override
    public BaseMapper<Company, String> getMapper() {
        return companyMapper;
    }

    public Company getCurrent() {
        SysUser sysUser = sysUserService.getCurrent();
        Map<String,Object> params = new HashMap<>();
        params.put("userId",sysUser.getId());
        List<Company> companyList = companyMapper.selectList(params);
        if (companyList.size()>0) {
            return companyList.get(0);
        } else {
            return null;
        }
    }

    //审核
    public int adopt(Long companyId){
        Company company=companyMapper.selectByPrimaryKey(companyId);
        company.setModifyDate(new Date());
        company.setStatus(2);

        int result=companyMapper.updateByPrimaryKeySelective(company);
        return result;
    }
    //驳回
    public int reject(Long companyId,String rejectText){
        Company company=companyMapper.selectByPrimaryKey(companyId);
        company.setModifyDate(new Date());
        company.setStatus(3);
        company.setMemo(rejectText);

        int result=companyMapper.updateByPrimaryKeySelective(company);
        return result;
    }

    //提交
    public int submit(Long companyId){
        Company  company=companyMapper.selectByPrimaryKey(companyId);
        company.setModifyDate(new Date());
        company.setStatus(1);

        int result=companyMapper.updateByPrimaryKeySelective(company);
        return result;
    }
}
